import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 通过router.push向当前页跳转时会报错，因为重复了
// 加上这一段代码就好
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

export default new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: ()=>import("@/components/login"),
      meta:{ title:"登录页面" }
    },
    {
      path: '/index',
      name: 'index',
      component: ()=>import("@/components/index"),
      children: [
        { 
          path: 'menu',
          name: 'menu1',
          component: ()=>import("@/components/menu1"),
          meta:{ title:"菜单页面" }
        },
        { 
          path: 'role',
          name: 'role',
          component: ()=>import("@/components/role"),
          meta:{ title:"角色页面" }
        },
        { 
          path: 'role/add',
          name: 'roleAdd',
          component: ()=>import("@/components/roleAdd"),
          meta:{ title:"添加角色" }
        },
        { 
          path: 'role/:id',
          name: 'roleEdit',
          component: ()=>import("@/components/roleAdd"),
          meta:{ title:"修改角色" }
        },
        { 
          path: 'admin',
          name: 'admin',
          component: ()=>import("@/components/admin"),
          meta:{ title:"管理员管理" }
        },
        { 
          path: 'category',
          name: 'category',
          component: ()=>import("@/components/category"),
          meta:{ title:"商品分类" }
        },
        { 
          path: 'category/add',
          name: 'categoryAdd',
          component: ()=>import("@/components/categoryAdd"),
          meta:{ title:"添加分类" }
        },{ 
          path: 'goods',
          name: 'goods',
          component: ()=>import("@/components/goods"),
          meta:{ title:"商品管理" }
        },
      ]
    }
  ]
})
